import { createApp } from 'vue'
import App from './App.vue'
import { setToken, getTokenFromCookie } from './utils/auth'
import Cookies from 'js-cookie'

import './style.css'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import locale from 'element-plus/es/locale/lang/zh-cn'

import router from "./router";

const app = createApp(App)

router.beforeEach(async(to, from, next) => {
    await setToken()
    if(getTokenFromCookie()){
        next()
    }
})

app.use(router);
// 使用element-plus 并且设置全局的大小
app.use(ElementPlus, {
    locale: locale,
    // 支持 large、default、small
    size: Cookies.get('size') || 'default'
})
app.mount('#app')
